import 'package:flutter/material.dart';
import 'package:motion_toast/motion_toast.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

/// Magma 提示组件
class MagmaToast {
  /// 显示成功提示
  static void success(
    BuildContext context, {
    required String title,
    String? description,
    Duration? duration,
  }) {
    MotionToast.success(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w600,
          color: Colors.white,
        ),
      ),
      description:
          description != null
              ? Text(
                description,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.normal,
                  color: Colors.white.withOpacity(0.9),
                ),
              )
              : const SizedBox.shrink(),
      width: 300.w,
      height: description != null ? 80.h : 60.h,
      animationDuration: const Duration(milliseconds: 300),
      animationCurve: Curves.easeInOut,
      animationType: AnimationType.slideInFromTop,
      dismissable: true,
      toastDuration: duration ?? const Duration(seconds: 3),
    ).show(context);
  }

  /// 显示警告提示
  static void warning(
    BuildContext context, {
    required String title,
    String? description,
    Duration? duration,
  }) {
    MotionToast.warning(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w600,
          color: Colors.white,
        ),
      ),
      description:
          description != null
              ? Text(
                description,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.normal,
                  color: Colors.white.withOpacity(0.9),
                ),
              )
              : const SizedBox.shrink(),
      width: 300.w,
      height: description != null ? 80.h : 60.h,
      animationDuration: const Duration(milliseconds: 300),
      animationCurve: Curves.easeInOut,
      dismissable: true,
      toastDuration: duration ?? const Duration(seconds: 3),
    ).show(context);
  }

  /// 显示错误提示
  static void error(
    BuildContext context, {
    required String title,
    String? description,
    Duration? duration,
  }) {
    MotionToast.error(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w600,
          color: Colors.white,
        ),
      ),
      description:
          description != null
              ? Text(
                description,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.normal,
                  color: Colors.white.withOpacity(0.9),
                ),
              )
              : const SizedBox.shrink(),
      width: 300.w,
      height: description != null ? 80.h : 60.h,
      animationDuration: const Duration(milliseconds: 300),
      animationCurve: Curves.easeInOut,
      dismissable: true,
      toastDuration: duration ?? const Duration(seconds: 3),
    ).show(context);
  }

  /// 显示信息提示
  static void info(
    BuildContext context, {
    required String title,
    String? description,
    Duration? duration,
  }) {
    MotionToast.info(
      title: Text(
        title,
        style: TextStyle(
          fontSize: 16.sp,
          fontWeight: FontWeight.w600,
          color: Colors.white,
        ),
      ),
      description:
          description != null
              ? Text(
                description,
                style: TextStyle(
                  fontSize: 14.sp,
                  fontWeight: FontWeight.normal,
                  color: Colors.white.withOpacity(0.9),
                ),
              )
              : const SizedBox.shrink(),
      width: 300.w,
      height: description != null ? 80.h : 60.h,
      animationDuration: const Duration(milliseconds: 300),
      animationCurve: Curves.easeInOut,
      dismissable: true,
      toastDuration: duration ?? const Duration(seconds: 3),
    ).show(context);
  }
}
